package com.tiny.mirror.service.product.application.convert;

import com.api.tiny.mirror.service.product.request.CreatePlatformRequest;
import com.api.tiny.mirror.service.product.request.UpdatePlatformRequest;
import com.api.tiny.mirror.service.product.response.DashboardPlatformDetailVO;
import com.api.tiny.mirror.service.product.response.PlatformVO;
import com.tiny.mirror.service.product.domain.platform.Platform;
import com.tiny.mirror.service.product.domain.platform.PlatformParams;
import com.tiny.mirror.service.product.infrastructure.entity.db.PlatformEntity;
import java.util.List;
import java.util.stream.Collectors;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.apache.commons.collections4.CollectionUtils;

/**
 * @Author: liujsh
 * @Description:
 * @Date: Create in 2023/10/8
 */
@SuppressWarnings("CPD-START")
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class PlatformConvert {

  public static List<PlatformVO> convertToPlatformVOList(List<Platform> list) {
    if (CollectionUtils.isEmpty(list)) {
      return null;
    }
    return list.stream().map(l -> convertToPlatformVO(l)).collect(Collectors.toList());
  }

  public static List<PlatformVO> convertEntityListToPlatformVOList(List<PlatformEntity> list) {
    if (CollectionUtils.isEmpty(list)) {
      return null;
    }
    return list.stream().map(l -> convertToPlatformVO(l)).collect(Collectors.toList());
  }

  public static List<DashboardPlatformDetailVO> convertEntityListToDashboardPlatformDetailVOList(
      List<PlatformEntity> list) {
    if (CollectionUtils.isEmpty(list)) {
      return null;
    }
    return list.stream().map(l -> convertToDashboardPlatformDetailVO(l))
        .collect(Collectors.toList());
  }

  public static PlatformVO convertToPlatformVO(Platform item) {
    if (item == null) {
      return null;
    }
    PlatformVO result = new PlatformVO();
    result.setId(item.getId());
    result.setAppId(item.getAppId());
    result.setType(item.getType());
    result.setName(item.getName());
    result.setStatus(item.getStatus());
    result.setOrderNum(item.getOrderNum());
    result.setCreateTime(item.toEntity().getCreateTime());
    result.setUpdateTime(item.toEntity().getUpdateTime());
    return result;
  }

  public static PlatformVO convertToPlatformVO(PlatformEntity item) {
    if (item == null) {
      return null;
    }
    PlatformVO result = new PlatformVO();
    result.setId(item.getId());
    result.setAppId(item.getAppId());
    result.setType(item.getType());
    result.setName(item.getName());
    result.setStatus(item.getStatus());
    result.setOrderNum(item.getOrderNum());
    result.setCreateTime(item.getCreateTime());
    result.setUpdateTime(item.getUpdateTime());
    return result;
  }

  public static DashboardPlatformDetailVO convertToDashboardPlatformDetailVO(PlatformEntity item) {
    if (item == null) {
      return null;
    }
    DashboardPlatformDetailVO result = new DashboardPlatformDetailVO();
    result.setId(item.getId());
    result.setType(item.getType());
    result.setName(item.getName());
    result.setPreviewUrl(item.getParams().getPreviewUrl());
    return result;
  }

  public static Platform convertToPlatform(CreatePlatformRequest request) {
    if (request == null) {
      return null;
    }
    Platform result = new Platform();
    result.setAppId(request.getAppId());
    result.setType(request.getType());
    result.setName(request.getName());
    result.setStatus(request.getStatus());
    PlatformParams appParams = new PlatformParams();
    appParams.setPreviewUrl(request.getPreviewUrl());
    result.setParams(appParams);
    result.setOrderNum(request.getOrderNum());
    return result;
  }

  public static Platform convertToPlatform(UpdatePlatformRequest request) {
    if (request == null) {
      return null;
    }
    Platform result = new Platform();
    result.setType(request.getType());
    result.setName(request.getName());
    PlatformParams appParams = new PlatformParams();
    appParams.setPreviewUrl(request.getPreviewUrl());
    result.setParams(appParams);
    result.setStatus(request.getStatus());
    result.setOrderNum(request.getOrderNum());
    return result;
  }
}
